package com.poizon.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.poizon.entity.RecordMoment;
import com.poizon.vo.MomentDetailsVo;
import com.poizon.vo.MomentVo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

/**
 * @ClassName RecordMomentDao
 * @Author NoCheng
 * @Date 2022/1/3 15:43
 * @Description:TODO 动态
 */

public interface RecordMomentDao extends BaseMapper<RecordMoment> {
    @Select("select m.id, m.cover, m.title, u.face, u.nickname, m.likes_number " +
            " from t_record_moment m " +
            " inner join t_item_number i on m.item_id = i.id " +
            " inner join t_brand b on i.brand_id = b.id " +
            " inner join t_userinfo u on m.userinfo_id = u.id " +
            " ${ew.customSqlSegment}")
    IPage<MomentVo> queryPageByItem(IPage<RecordMoment> page, @Param(Constants.WRAPPER)QueryWrapper<RecordMoment> wrapper);

    @Select("select m.id, m.cover, m.title, u.face, u.nickname, m.likes_number " +
            " from t_record_moment m " +
            " inner join t_userinfo u on m.userinfo_id = u.id " +
            " ${ew.customSqlSegment}")
    IPage<MomentVo> queryPage(IPage<RecordMoment> page, @Param(Constants.WRAPPER)QueryWrapper<RecordMoment> wrapper);

    @Select("select brand_name from t_brand")
    @ResultType(String.class)
    Set<String> queryBrandName();

    @Select("select m.userinfo_id, u.face, u.nickname," +
            " m.id, m.publish_time, m.picture, m.likes_number," +
            " m.comment_number, m.title, m.moment_content," +
            " m.item_id, i.item_info, i.item_picture" +
            " from t_record_moment m" +
            " left join t_userinfo u on m.userinfo_id = u.id" +
            " left join t_item_number i on m.item_id = i.id" +
            " where m.id = #{id}")
    @Results(value = {
            @Result(property = "id", column = "id", id = true),
            @Result(property = "userinfoId", column = "userinfo_id"),
            @Result(property = "face", column = "face"),
            @Result(property = "nickname", column = "nickname"),
            @Result(property = "publishTime", column = "publish_time"),
            @Result(property = "picture", column = "picture"),
            @Result(property = "likesNumber", column = "likes_number"),
            @Result(property = "commentNumber", column = "comment_number"),
            @Result(property = "title", column = "title"),
            @Result(property = "momentContent", column = "moment_content"),
            @Result(property = "itemId", column = "item_id"),
            @Result(property = "itemPicture", column = "item_picture"),
            @Result(property = "itemInfo", column = "item_info"),
            @Result(property = "comments", javaType = List.class, column = "id",
                    many = @Many(select = "com.poizon.dao.MomentCommentDao.queryComment"))
    })
    MomentDetailsVo queryDetails(Long id);
}
